package edu.imac.angryfood.render;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

import edu.imac.angryfood.world.Body;
/**
 * Manages the camera 
 * 
 */
public class Camera {
	
	private int x;
	private int y;
	private int dx;
	private int dy;
	private float scale;
	private float dscale;
	private int projFollowed;
	
	
	/**
	 *  return the zoom of the camera
	 * @param scale
	 */
	public void setScale(float scale) {
		this.scale = scale;
	}
	
	/**
	 * Constructor of the camera
	 * @param x
	 * @param y
	 * @param scale
	 */
	public Camera(int x, int y, float scale) {
		super();
		this.x = x;
		this.y = y;
		this.scale = scale;
		this.dx = 3;
		this.dy = 3;
		this.dscale = 0.03f;
		projFollowed=0;
	}
	
	/**
	 * get the projectile followed
	 * @return the projectile followed
	 */
	public int getProjFollowed() {
		return projFollowed;
	}

	/**
	 * set the projectile followed
	 */
	public void setProjFollowed(int projFollowed) {
		this.projFollowed = projFollowed;
	}

	/**
	 * move the camera on the X axis Right if direction = 1
	 * left if direction = -1
	 * @param direction
	 */
	public void deplaX(int direction) {
		if(this.x > 0 && this.x < 1000)
			this.x += (this.dx*direction);
		if(this.x <= 0)
			this.x = 1;
		if(this.x >= 1000)
			this.x = 999;
	}
	
	/**
	 * get the x of the camera
	 * @return x of the camera 
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * get the y of the camera
	 * @return y of the camera 
	 */
	public int getY() {
		return y;
	}

	/**
	 * move the camera on the Y axis Top if direction = 1
	 * down if direction = -1
	 * @param direction
	 */
	public void deplaY(int direction) {
		this.y += (this.dx*direction);
	}
	
	/**
	 * zoom in or out with if direction = 1 or -1
	 * @param direction
	 */
	public void zoom(int direction) {
		if(direction < 0f) {
			if(scale > 0.65f){
				this.scale += (this.dscale*direction);
				this.y += 9;
			}
			else
				this.scale = 0.65f;
		}
		else {
			this.scale += (this.dscale*direction);
			this.y -= 9;
		}
	}

	/**
	 * move the camera at the coordinate
	 * @param x
	 * @param y
	 * @param scale
	 */
	public void setPosition(int x, int y, float scale) {		
		this.scale = scale;
		this.x = -x;
		this.y = y;
	}
	
	/**
	 * display the stage where the coordinate of the camera are
	 * @param container
	 * @param graphics g
	 */
	public void display(GameContainer container, Graphics g) {
		g.translate(0,(container.getHeight() / 2));
		g.translate((container.getWidth() / 2), 0);
		g.translate(-this.x, this.y);
		// zoom		
		g.scale(1*this.scale, -1*this.scale);

	}
	
	/**
	 * Move the camera a the center
	 * @param container
	 * @param g
	 */
	public void setCenter(GameContainer container, Graphics g) {
		g.translate(0,(container.getHeight() / 2));
		g.translate((container.getWidth() / 2), 0);
		g.translate(-x, y);
		// zoom		
		g.scale(1*scale, -1*scale);
		
		this.scale = 1;
		this.x = 0;
		this.y = 0;
	}
	
	/**
	 * set the x of the camera
	 * @param x
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * set the y of the camera
	 * @param y
	 */
	public void setY(int y) {
		this.y = y;
	}
	
	/**
	 * get the scale of the camera
	 * @return
	 */
	public float getScale() {
		return scale;
	}
	
	/**
	 * follow a body instead of the keyboard control
	 * @param body
	 */
	public void followBody(Body body) {
		this.x = (int)(body.getX()+220);
	}
	
	/**
	 * get DX
	 * @return dx
	 */
	public int getDx() {
		return dx;
	}
	
	/**
	 * set the DX
	 * @param dx
	 */
	public void setDx(int dx) {
		this.dx = dx;
	}
	
	/**
	 * get the Dy
	 * @return dy
	 */
	public int getDy() {
		return dy;
	}

	/**
	 * set Dy
	 * @param dy
	 */
	public void setDy(int dy) {
		this.dy = dy;
	}
}


